package org.russianpost;

import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class StatusList {
    // Status mapping by status code and substatus code
    private final Map<String, Map<String, String>> statusMap = new HashMap<>();
    private final Map<Integer, String> statusNameList = new HashMap<>();

    public StatusList() {
        initializeStatusMap();
        initializeStatusNameList();
    }

    private void initializeStatusMap() {
        // Acceptance
        Map<String, String> status1 = new HashMap<>();
        status1.put("1", "Single");
        status1.put("2", "Batch");
        status1.put("3", "Electronic batch");
        status1.put("4", "Simplified single");
        status1.put("5", "By list at distribution center");
        status1.put("6", "By list at sorting center");
        status1.put("7", "Simplified pre-filled");
        status1.put("8", "Simplified prepaid");
        status1.put("9", "According to forwarding agent's order");
        status1.put("10", "By addressee's request");
        statusMap.put("1", status1);

        // Delivery
        Map<String, String> status2 = new HashMap<>();
        status2.put("0", "");
        status2.put("1", "Delivered to addressee"); // Final
        status2.put("2", "Delivered to sender"); // Final
        status2.put("3", "Issued to addressee via parcel locker"); // Final
        status2.put("4", "Issued to sender via parcel locker"); // Final
        status2.put("5", "Delivered to addressee electronically"); // Final
        status2.put("6", "Delivered to addressee by postman"); // Final
        status2.put("7", "Delivered to sender by postman"); // Final
        status2.put("8", "Delivered to addressee by courier"); // Final
        status2.put("9", "Delivered to sender by courier"); // Final
        status2.put("10", "Delivered to addressee with response control"); // Final
        status2.put("11", "Delivered to addressee with response control by postman"); // Final
        status2.put("12", "Delivered to addressee with response control by courier"); // Final
        status2.put("13", "Delivered to addressee via PES"); // Final
        status2.put("14", "For digitization"); // Final
        status2.put("15", "Delivered to addressee by Forwarder"); // Final
        status2.put("16", "Delivered to sender by Forwarder"); // Final
        status2.put("17", "Delivered to addressee by postman via PES"); // Final
        status2.put("18", "Delivered to addressee by courier via PES"); // Final
        status2.put("19", "Delivered to addressee by robot courier"); // Final
        status2.put("20", "Delivered to sender by robot courier"); // Final
        status2.put("21", "Delivered to addressee via AAPS"); // Final
        status2.put("22", "Delivered to sender via AAPS"); // Final
        status2.put("23", "Delivered to addressee via APSH"); // Final
        status2.put("24", "Delivered to sender via APSH"); // Final
        statusMap.put("2", status2);

        // Return
        Map<String, String> status3 = new HashMap<>();
        status3.put("1", "Storage period expired");
        status3.put("2", "Sender's request");
        status3.put("3", "Addressee not at specified address");
        status3.put("4", "Addressee refused");
        status3.put("5", "Addressee deceased");
        status3.put("6", "Unable to read addressee's address");
        status3.put("7", "Customs release refused");
        status3.put("8", "Mailbox subscriber not specified or incorrect");
        status3.put("9", "Other circumstances");
        status3.put("10", "Incorrect address");
        status3.put("11", "Incomplete set");
        status3.put("12", "Prohibited by SAB");
        status3.put("13", "For customs operations");
        status3.put("14", "ETP order");
        status3.put("15", "Partial redemption");
        status3.put("16", "By agreement with addressee");
        status3.put("17", "Recipient age mismatch (18+)");
        status3.put("18", "Parcel locker closed");
        status3.put("19", "Parcel locker refused to accept");
        statusMap.put("3", status3);

        // Additional delivery
        Map<String, String> status4 = new HashMap<>();
        status4.put("1", "By user request");
        status4.put("2", "Addressee moved to new address");
        status4.put("3", "Missent");
        status4.put("4", "Prohibited by SAB");
        status4.put("5", "Transferred to temporary storage");
        status4.put("6", "Transferred to unclaimed");
        status4.put("7", "Technical reasons");
        status4.put("8", "By agreement with addressee");
        status4.put("9", "No PES");
        status4.put("10", "Payment required for TPO");
        status4.put("11", "Defective shipment");
        status4.put("12", "Exceeds size limits");
        status4.put("13", "Storage period expired in APS");
        status4.put("14", "No available cells");
        status4.put("15", "PES connected");
        status4.put("16", "TPO paid");
        status4.put("17", "PES connected and TPO paid");
        status4.put("18", "By user request for specific RPO");
        status4.put("19", "By addressee request for all incoming RPO");
        statusMap.put("4", status4);

        // Non-delivery
        Map<String, String> status5 = new HashMap<>();
        status5.put("1", "Lost"); // Final
        status5.put("2", "Seized"); // Final
        status5.put("3", "Missent");
        status5.put("8", "Customs decision");
        status5.put("9", "(reserved)");
        statusMap.put("5", status5);

        // Storage
        Map<String, String> status6 = new HashMap<>();
        status6.put("1", "On demand");
        status6.put("2", "To subscription box");
        status6.put("3", "Standard storage period");
        status6.put("4", "Storage extended by addressee request");
        status6.put("5", "Storage extended by sender request");
        statusMap.put("6", status6);

        // Temporary storage
        Map<String, String> status7 = new HashMap<>();
        status7.put("1", "Not issued");
        status7.put("2", "Unclaimed");
        status7.put("3", "Contents prohibited for mailing");
        status7.put("4", "Awaiting examination results");
        statusMap.put("7", status7);

        // Processing
        Map<String, String> status8 = new HashMap<>();
        status8.put("0", "Sorting");
        status8.put("1", "Left acceptance point");
        status8.put("2", "Arrived at delivery point");
        status8.put("3", "Arrived at sorting center");
        status8.put("4", "Left sorting center");
        status8.put("5", "Arrived at international exchange point");
        status8.put("6", "Left international exchange point");
        status8.put("7", "Arrived at transit point");
        status8.put("8", "Left transit point");
        status8.put("9", "Arrived at parcel locker");
        status8.put("10", "Storage period in parcel locker expiring");
        status8.put("11", "Redirected to parcel locker");
        status8.put("12", "Retrieved from parcel locker");
        status8.put("13", "Arrived in Russian Federation");
        status8.put("14", "Arrived at parcel center");
        status8.put("15", "Handed to courier");
        status8.put("16", "Delivered for electronic delivery");
        status8.put("17", "Arrived at CGP");
        status8.put("18", "Handed to postman");
        status8.put("19", "Transferred to storage room");
        status8.put("20", "Left return/additional delivery point");
        status8.put("21", "Address clarification");
        status8.put("22", "Awaiting courier delivery");
        status8.put("23", "Storage period extended");
        status8.put("24", "Notification sent");
        status8.put("25", "Notification delivered");
        status8.put("26", "Registered with new number");
        status8.put("27", "Storage period expiring (25 days left)");
        status8.put("28", "Storage period expiring (5 days left)");
        status8.put("29", "Under technical examination");
        status8.put("30", "Arrived at CGP");
        status8.put("31", "Left CGP");
        status8.put("32", "Sent to UCD");
        status8.put("33", "Storage period expiring (23 days left)");
        status8.put("34", "Before data entry");
        status8.put("35", "Storage period expiring (10 days left)");
        status8.put("36", "Return request registered");
        status8.put("37", "Sender's storage extension request registered");
        status8.put("38", "Addressee's storage extension request registered");
        status8.put("39", "Submitted to PVP");
        status8.put("40", "Storage period expired");
        status8.put("41", "Return compiled");
        status8.put("42", "Storage period expiring (1 day left)");
        status8.put("43", "Storage period expired (2 days left)");
        status8.put("44", "Submitted to SC");
        status8.put("45", "Reserve");
        status8.put("46", "Reserve");
        status8.put("47", "Processing suspended by Federal Law 115");
        status8.put("48", "Assigned to address storage");
        status8.put("49", "Sent to pickup point");
        status8.put("50", "Request sent to call center");
        status8.put("51", "Weight recorded after customs inspection");
        status8.put("52", "Delivery permitted");
        status8.put("53", "Delivery not permitted");
        status8.put("54", "Parcel locker cell reserved, shipment in queue");
        status8.put("55", "Awaiting placement");
        status8.put("56", "Storage at address post office 2 days before expiration");
        status8.put("57", "Storage at address post office 5 days after delivery");
        status8.put("58", "Storage at address PVP for 5 days");
        status8.put("59", "Storage at address post office 5 days after delivery");
        status8.put("60", "Placed in APSH/AAPS cell");
        status8.put("61", "Addressee's additional delivery request registered");
        status8.put("62", "Transferred to client hall");
        status8.put("63", "Request sent to CC");
        status8.put("64", "Retrieved from APSH/AAPS");
        status8.put("65", "Shipment missing");
        status8.put("66", "Request for consent to delivery via PO box");
        status8.put("67", "Consent for delivery via PO box");
        status8.put("68", "Handed to courier for delivery to APS");
        status8.put("69", "Handed to courier for delivery to PVP");
        status8.put("70", "Accepted by courier for delivery to UCD");
        status8.put("71", "Sent to delivery post office");
        status8.put("72", "Sent to UOPK");
        status8.put("73", "Arrived at UOPK");
        status8.put("74", "Placed in APS cell");
        status8.put("75", "Retrieved from APS");
        status8.put("76", "Forced redirection to post office");
        statusMap.put("8", status8);

        // International mail import
        Map<String, String> status9 = new HashMap<>();
        status9.put("0", "International mail import");
        statusMap.put("9", status9);

        // International mail export
        Map<String, String> status10 = new HashMap<>();
        status10.put("0", "International mail export");
        statusMap.put("10", status10);

        // Customs acceptance
        Map<String, String> status11 = new HashMap<>();
        status11.put("0", "Customs acceptance");
        statusMap.put("11", status11);

        // Failed delivery attempt
        Map<String, String> status12 = new HashMap<>();
        status12.put("1", "Addressee temporarily absent");
        status12.put("2", "Delivery postponed by addressee request");
        status12.put("3", "Incomplete address");
        status12.put("4", "Incorrect address");
        status12.put("5", "Addressee moved");
        status12.put("6", "Addressee refused");
        status12.put("7", "Force majeure");
        status12.put("8", "Other");
        status12.put("9", "Addressee will pick up themselves");
        status12.put("10", "No addressee");
        status12.put("11", "Technical reasons");
        status12.put("12", "Storage period in parcel locker expired");
        status12.put("13", "By sender request");
        status12.put("14", "Damaged shipment and/or empty");
        status12.put("15", "Awaiting fee payment");
        status12.put("16", "Addressee relocated");
        status12.put("17", "Addressee has PO box");
        status12.put("18", "No home delivery");
        status12.put("19", "Does not meet customs requirements");
        status12.put("20", "Incomplete/insufficient/incorrect documents");
        status12.put("21", "Cannot contact client");
        status12.put("22", "Addressee on strike");
        status12.put("23", "Prohibited contents - not delivered");
        status12.put("24", "Import refused - prohibited contents");
        status12.put("25", "Missent shipment");
        status12.put("26", "Recipient deceased");
        status12.put("27", "National holiday");
        status12.put("28", "Lost");
        status12.put("29", "By addressee order");
        status12.put("30", "Recipient age mismatch (18+)");
        statusMap.put("12", status12);

        // Shipment registration
        Map<String, String> status13 = new HashMap<>();
        status13.put("0", "Shipment registration");
        statusMap.put("13", status13);

        // Customs clearance
        Map<String, String> status14 = new HashMap<>();
        status14.put("1", "Released by customs");
        status14.put("2", "Returned by customs");
        status14.put("3", "Inspected by customs");
        status14.put("4", "Release refused");
        status14.put("5", "Sent with customs notification");
        status14.put("6", "Sent with mandatory customs payment");
        status14.put("7", "Inspection required");
        status14.put("8", "Release suspended");
        status14.put("9", "Customs acceptance refused");
        status14.put("10", "Inspected using TSTK");
        status14.put("11", "TC under SUR*");
        status14.put("12", "Inspection completed");
        status14.put("13", "Release permitted. Customs fees paid");
        status14.put("14", "Release refused. Customs fees not paid");
        status14.put("15", "Customs declaration failed FLK");
        status14.put("16", "Released by customs. Funds reserved");
        status14.put("17", "Release refused by official decision");
        status14.put("18", "Presentation at TO required");
        status14.put("19", "Automatic release refused");
        status14.put("20", "Release refused. Goods not presented");
        status14.put("21", "Inspection results required");
        status14.put("22", "Return permitted");
        status14.put("23", "Release of returned goods refused");
        status14.put("24", "X-ray control required");
        status14.put("25", "Departure refused");
        status14.put("26", "Departure permitted");
        statusMap.put("14", status14);

        // Transfer to temporary storage
        Map<String, String> status15 = new HashMap<>();
        status15.put("0", "Transfer to temporary storage");
        statusMap.put("15", status15);

        // Destruction
        Map<String, String> status16 = new HashMap<>();
        status16.put("0", "Destruction");
        statusMap.put("16", status16);

        // Transfer of contents to balance
        Map<String, String> status17 = new HashMap<>();
        status17.put("0", "Transfer of contents to balance");
        statusMap.put("17", status17);

        // Loss registration
        Map<String, String> status18 = new HashMap<>();
        status18.put("0", "Loss registration");
        statusMap.put("18", status18);

        // Customs payments received
        Map<String, String> status19 = new HashMap<>();
        status19.put("0", "Customs payments received");
        statusMap.put("19", status19);

        // Registration
        Map<String, String> status20 = new HashMap<>();
        status20.put("0", "Registration");
        statusMap.put("20", status20);

        // Delivery
        Map<String, String> status21 = new HashMap<>();
        status21.put("1", "Delivered to mailbox");
        status21.put("2", "Delivered to addressee in person with signature");
        status21.put("3", "Delivered to reception/secretariat with signature");
        statusMap.put("21", status21);

        // Non-delivery
        Map<String, String> status22 = new HashMap<>();
        status22.put("1", "No mailbox");
        status22.put("2", "No street/house/apartment");
        status22.put("3", "Post office index mismatch");
        status22.put("4", "Incorrect/non-existent address");
        status22.put("5", "Refused to accept");
        status22.put("6", "No access to address");
        status22.put("7", "Organization changed address");
        status22.put("8", "Addressee moved");
        status22.put("9", "Shipment doesn't fit in mailbox");
        statusMap.put("22", status22);

        // Arrival at temporary storage
        Map<String, String> status23 = new HashMap<>();
        status23.put("0", "Arrival at temporary storage");
        statusMap.put("23", status23);

        // Customs release extension
        Map<String, String> status24 = new HashMap<>();
        status24.put("1", "Present for veterinary control");
        status24.put("2", "Present for phytosanitary control");
        status24.put("3", "Sampling");
        status24.put("4", "Other");
        status24.put("5", "Cannot contact client for information");
        status24.put("1019", "Prohibited items");
        status24.put("1020", "Import restrictions on contents");
        status24.put("1050", "No invoice");
        status24.put("1051", "Incorrect invoice");
        status24.put("1052", "Missing or incorrect certificate");
        status24.put("1053", "Incorrect certificate");
        status24.put("1054", "Missing or incorrect customs declaration");
        status24.put("1055", "Incorrect CN 22/23");
        status24.put("1056", "High-value contents - TD required");
        status24.put("1057", "Cannot contact client");
        status24.put("1058", "Awaiting transfer to customs");
        status24.put("1059", "VAT/Import number required");
        status24.put("1060", "Certificate required for returned contents");
        status24.put("1061", "Bank transfer form required");
        status24.put("1062", "Incomplete shipment");
        status24.put("1063", "Transferred to customs");
        status24.put("1064", "Detained by customs without reason");
        status24.put("1065", "Awaiting recipient's value confirmation");
        status24.put("1070", "Export restrictions on contents");
        status24.put("1073", "Incomplete or incorrect documentation");
        status24.put("1099", "Other");
        statusMap.put("24", status24);

        // Opening
        Map<String, String> status25 = new HashMap<>();
        status25.put("0", "Opening");
        statusMap.put("25", status25);

        // Cancellation
        Map<String, String> status26 = new HashMap<>();
        status26.put("1", "Sender's request");
        status26.put("2", "Operator error");
        statusMap.put("26", status26);

        // Electronic registration received
        Map<String, String> status27 = new HashMap<>();
        status27.put("0", "Electronic registration received");
        statusMap.put("27", status27);

        // ID assignment
        Map<String, String> status28 = new HashMap<>();
        status28.put("0", "ID assignment");
        statusMap.put("28", status28);

        // MMPO passage registration
        Map<String, String> status29 = new HashMap<>();
        status29.put("0", "MMPO passage registration");
        statusMap.put("29", status29);

        // SRM sending
        Map<String, String> status30 = new HashMap<>();
        status30.put("0", "SRM sending");
        statusMap.put("30", status30);

        // Carrier processing
        Map<String, String> status31 = new HashMap<>();
        status31.put("1", "Transport arrived");
        status31.put("5", "Booking confirmed");
        status31.put("6", "Included in loading plan");
        status31.put("7", "Excluded from loading plan");
        status31.put("14", "Transport section completed");
        status31.put("21", "Delivered");
        status31.put("23", "Mail at destination");
        status31.put("24", "Loaded on board");
        status31.put("31", "In transit");
        status31.put("40", "Arrived at carrier's warehouse");
        status31.put("41", "Transshipment");
        status31.put("42", "Transferred to another carrier");
        status31.put("43", "Received from another carrier");
        status31.put("48", "Loaded");
        status31.put("57", "Not loaded");
        status31.put("59", "Unloaded");
        status31.put("74", "Accepted for transportation");
        status31.put("82", "Returned");
        statusMap.put("31", status31);

        // APO arrival
        Map<String, String> status32 = new HashMap<>();
        status32.put("0", "APO arrival");
        statusMap.put("32", status32);

        // International processing
        Map<String, String> status33 = new HashMap<>();
        status33.put("1", "Transferred to carrier");
        status33.put("2", "Received by designated operator");
        status33.put("3", "Processing by designated operator");
        statusMap.put("33", status33);

        // Electronic notification uploaded
        Map<String, String> status34 = new HashMap<>();
        status34.put("0", "Electronic notification uploaded");
        statusMap.put("34", status34);

        // Courier delivery refusal
        Map<String, String> status35 = new HashMap<>();
        status35.put("1", "Non-deliverable mail type");
        status35.put("2", "Exceeds maximum deliverable weight");
        status35.put("3", "Exceeds maximum deliverable dimensions");
        status35.put("4", "Defective mail item");
        status35.put("5", "Customs notification present");
        status35.put("6", "No agreement for COD mail exchange");
        status35.put("7", "Returned mail item");
        status35.put("8", "Exceeds maximum collectable COD amount");
        status35.put("9", "Incorrect or missing forms");
        statusMap.put("35", status35);

        // Delivery payment type clarification
        Map<String, String> status36 = new HashMap<>();
        status36.put("0", "Included in tariff");
        status36.put("1", "Paid");
        status36.put("2", "Prepaid");
        statusMap.put("36", status36);

        // Preliminary processing
        Map<String, String> status37 = new HashMap<>();
        status37.put("0", "Preliminary processing");
        statusMap.put("37", status37);

        // Delay for sender clarification
        Map<String, String> status38 = new HashMap<>();
        status38.put("4", "Incorrect/unreadable/incomplete address");
        status38.put("13", "By sender request");
        status38.put("25", "Missent shipment");
        statusMap.put("38", status38);

        // Preliminary customs declaration
        Map<String, String> status39 = new HashMap<>();
        status39.put("1", "Registration");
        status39.put("2", "Preliminary \"release permitted\" decision");
        status39.put("3", "Release refused. Presentation to customs without inspection required");
        status39.put("4", "Release refused. Presentation to customs with inspection required");
        status39.put("5", "Registration refused");
        status39.put("6", "Release refused. Goods not presented");
        status39.put("7", "Data from trading platform received");
        status39.put("8", "Release permitted");
        status39.put("9", "Release refused");
        statusMap.put("39", status39);

        // Customs control
        Map<String, String> status40 = new HashMap<>();
        status40.put("1", "Payments paid");
        status40.put("2", "Control notification");
        status40.put("3", "Release refused by official decision");
        statusMap.put("40", status40);

        // Customs payments processing
        Map<String, String> status41 = new HashMap<>();
        status41.put("1", "Payment amount withheld by UO");
        status41.put("2", "Payment amount written off by FTS");
        status41.put("3", "Payment amount for withholding by UO");
        status41.put("4", "Payment amount fully withheld by UO");
        status41.put("5", "Payment amount calculated by UO");
        status41.put("6", "Payment amount fully withheld by FTS");
        statusMap.put("41", status41);

        // Second failed delivery attempt
        Map<String, String> status42 = new HashMap<>();
        status42.put("1", "Addressee temporarily absent");
        status42.put("2", "Delivery postponed by addressee request");
        status42.put("3", "Incomplete address");
        status42.put("4", "Incorrect/unreadable/incomplete address");
        status42.put("5", "Addressee moved");
        status42.put("6", "Addressee refused shipment");
        status42.put("7", "Force majeure");
        status42.put("8", "Other");
        status42.put("9", "Addressee will pick up themselves");
        status42.put("10", "Addressee unavailable");
        status42.put("11", "Failed delivery");
        status42.put("12", "Storage period in parcel locker expired");
        status42.put("13", "By sender request");
        status42.put("14", "Damaged shipment and/or empty");
        status42.put("15", "Awaiting fee payment");
        status42.put("16", "Addressee relocated");
        status42.put("17", "Addressee has PO box");
        status42.put("18", "No home delivery");
        status42.put("19", "Does not meet customs requirements");
        status42.put("20", "Incomplete/insufficient/incorrect documents");
        status42.put("21", "Cannot contact client");
        status42.put("22", "Addressee on strike");
        status42.put("23", "Prohibited contents - not delivered");
        status42.put("24", "Import refused - prohibited contents");
        status42.put("25", "Missent shipment");
        status42.put("26", "Recipient deceased");
        status42.put("27", "National holiday");
        status42.put("28", "Lost");
        status42.put("29", "By addressee order");
        statusMap.put("42", status42);

        // Delivery permitted
        Map<String, String> status43 = new HashMap<>();
        status43.put("0", "Delivery permitted");
        statusMap.put("43", status43);

        // Acceptance refused
        Map<String, String> status44 = new HashMap<>();
        status44.put("1", "Tariff application violation");
        status44.put("2", "Actual weight mismatch");
        status44.put("3", "Format mismatch");
        status44.put("4", "Unreadable barcode");
        status44.put("5", "Package damage");
        status44.put("6", "GZPO authenticity violation");
        status44.put("7", "RPO barcode scanned earlier");
        status44.put("8", "Address error");
        status44.put("9", "Exceeds size limits");
        status44.put("10", "Incorrect sender index");
        status44.put("11", "Incorrect ZOO");
        status44.put("12", "Shipment missing");
        status44.put("13", "Contents mismatch");
        status44.put("14", "Return by contract terms");
        statusMap.put("44", status44);

        // Electronic notification refusal by recipient
        Map<String, String> status45 = new HashMap<>();
        status45.put("0", "Electronic notification refusal by recipient");
        statusMap.put("45", status45);

        // ID assignment cancellation
        Map<String, String> status46 = new HashMap<>();
        status46.put("0", "ID assignment cancellation");
        statusMap.put("46", status46);

        // Acceptance capability confirmation
        Map<String, String> status47 = new HashMap<>();
        status47.put("0", "Acceptance capability confirmation");
        statusMap.put("47", status47);

        // Partial delivery
        Map<String, String> status48 = new HashMap<>();
        status48.put("0", "Partial delivery");
        statusMap.put("48", status48);

        // Storage extension refusal
        Map<String, String> status49 = new HashMap<>();
        status49.put("1", "Already delivered");
        status49.put("2", "Storage extension request received again");
        status49.put("3", "Storage extension request submitted less than 24 hours before expiration");
        status49.put("4", "Corporate client has debt");
        status49.put("5", "Online store prohibited extension");
        status49.put("6", "PVP closed");
        statusMap.put("49", status49);

        // Failed APS delivery
        Map<String, String> status50 = new HashMap<>();
        status50.put("1", "APS missing");
        status50.put("2", "APS not working");
        status50.put("3", "No access to APS");
        status50.put("4", "Courier didn't make it");
        status50.put("5", "No available APS cells");
        status50.put("6", "Courier couldn't place");
        status50.put("7", "Opened cell smaller than shipment");
        status50.put("8", "Cell doesn't open, broken");
        statusMap.put("50", status50);

        // Failed PVP delivery
        Map<String, String> status51 = new HashMap<>();
        status51.put("1", "PVP temporarily closed");
        status51.put("2", "PVP permanently closed");
        status51.put("3", "PVP refused to accept");
        status51.put("4", "Courier didn't make it");
        statusMap.put("51", status51);

        // APS cell reservation refusal
        Map<String, String> status52 = new HashMap<>();
        status52.put("0", "APS cell reservation refusal");
        statusMap.put("52", status52);

        // Delivery interval booking
        Map<String, String> status53 = new HashMap<>();
        status53.put("1", "Delivery interval assigned upon arrival");
        status53.put("2", "Delivery interval assigned by online store");
        status53.put("3", "Delivery interval assigned by addressee");
        statusMap.put("53", status53);

        // Delivery interval change
        Map<String, String> status54 = new HashMap<>();
        status54.put("1", "Postponed by client agreement");
        status54.put("2", "Postponed by Russian Post initiative");
        statusMap.put("54", status54);

        // Delivery interval booking refusal
        Map<String, String> status55 = new HashMap<>();
        status55.put("1", "Return to sender");
        status55.put("2", "Self pickup");
        status55.put("3", "Technical reason");
        status55.put("4", "Sender submission deadline violated");
        status55.put("5", "Delivery request canceled by client");
        status55.put("6", "Shipment didn't arrive at delivery point");
        statusMap.put("55", status55);

        // Return to address post office
        Map<String, String> status56 = new HashMap<>();
        status56.put("1", "Addressee left RPO in AAPS cell");
        statusMap.put("56", status56);

        // MMO delivery method change
        Map<String, String> status58 = new HashMap<>();
        status58.put("0", "MMO delivery method change");
        statusMap.put("58", status58);

        // External ID registration
        Map<String, String> status59 = new HashMap<>();
        status59.put("0", "External ID registration");
        statusMap.put("59", status59);

        // Failed APS retrieval
        Map<String, String> status60 = new HashMap<>();
        status60.put("1", "APS cell empty");
        status60.put("2", "APS cell didn't open");
        status60.put("3", "APS not working");
        status60.put("4", "No access to APS");
        status60.put("5", "Defective shipment");
        statusMap.put("60", status60);

        // Transferred to departmental carrier
        Map<String, String> status61 = new HashMap<>();
        status61.put("0", "Transferred to departmental carrier");
        statusMap.put("61", status61);

        // Returned to client
        Map<String, String> status62 = new HashMap<>();
        status62.put("0", "Returned to client");
        statusMap.put("62", status62);

        // Shortage
        Map<String, String> status1027 = new HashMap<>();
        status1027.put("1", "Missing in container");
        status1027.put("2", "Missing during inventory");
        status1027.put("3", "Upon receipt from transport");
        status1027.put("4", "Missing at post office");
        statusMap.put("1027", status1027);
    }

    private void initializeStatusNameList() {
        statusNameList.put(1, "Acceptance");
        statusNameList.put(2, "Delivery");
        statusNameList.put(3, "Return");
        statusNameList.put(4, "Additional delivery");
        statusNameList.put(5, "Non-delivery");
        statusNameList.put(6, "Storage");
        statusNameList.put(7, "Temporary storage");
        statusNameList.put(8, "Processing");
        statusNameList.put(9, "International mail import");
        statusNameList.put(10, "International mail export");
        statusNameList.put(11, "Customs acceptance");
        statusNameList.put(12, "Failed delivery attempt");
        statusNameList.put(13, "Shipment registration");
        statusNameList.put(14, "Customs clearance");
        statusNameList.put(15, "Transfer to temporary storage");
        statusNameList.put(16, "Destruction");
        statusNameList.put(17, "Ownership registration");
        statusNameList.put(18, "Loss registration");
        statusNameList.put(19, "Customs payments received");
        statusNameList.put(20, "Registration");
        statusNameList.put(21, "Delivery");
        statusNameList.put(22, "Non-delivery");
        statusNameList.put(23, "Arrival at temporary storage");
        statusNameList.put(24, "Customs release extension");
        statusNameList.put(25, "Opening");
        statusNameList.put(26, "Cancellation");
        statusNameList.put(27, "Electronic registration received");
        statusNameList.put(28, "ID assignment");
        statusNameList.put(29, "MMPO passage registration");
        statusNameList.put(30, "SRM sending");
        statusNameList.put(31, "Carrier processing");
        statusNameList.put(32, "APO arrival");
        statusNameList.put(33, "International processing");
        statusNameList.put(34, "Electronic notification uploaded");
        statusNameList.put(35, "Courier delivery refusal");
        statusNameList.put(36, "Delivery payment type clarification");
        statusNameList.put(37, "Preliminary processing");
        statusNameList.put(38, "Delay for sender clarification");
        statusNameList.put(39, "Preliminary customs declaration");
        statusNameList.put(40, "Customs control");
        statusNameList.put(41, "Customs payments processing");
        statusNameList.put(42, "Second failed delivery attempt");
        statusNameList.put(43, "Delivery permitted");
        statusNameList.put(44, "Acceptance refused");
        statusNameList.put(45, "Electronic notification refusal by recipient");
        statusNameList.put(46, "ID assignment cancellation");
        statusNameList.put(47, "Acceptance capability confirmation");
        statusNameList.put(48, "Partial delivery");
        statusNameList.put(49, "Storage extension refusal");
        statusNameList.put(50, "Failed APS delivery");
        statusNameList.put(51, "Failed PVP delivery");
        statusNameList.put(52, "APS cell reservation refusal");
        statusNameList.put(53, "Delivery interval booking");
        statusNameList.put(54, "Delivery interval change");
        statusNameList.put(55, "Delivery interval booking refusal");
        statusNameList.put(56, "Return to address post office");
        statusNameList.put(58, "MMO delivery method change");
        statusNameList.put(59, "External ID registration");
        statusNameList.put(60, "Failed APS retrieval");
        statusNameList.put(61, "Transferred to departmental carrier");
        statusNameList.put(62, "Returned to client");
        statusNameList.put(1027, "Shortage");
    }

    /**
     * Checks if status is final
     * @return bool
     */
    public boolean isFinal(int statusId, int substatusId) {
        Map<Integer, int[]> finalList = new HashMap<>();
        finalList.put(2, new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24});
        finalList.put(5, new int[]{1, 2});
        finalList.put(15, new int[]{0});
        finalList.put(16, new int[]{0});
        finalList.put(17, new int[]{0});
        finalList.put(18, new int[]{0});
        if (finalList.containsKey(statusId)) {
            for (int id : finalList.get(statusId)) {
                if (id == substatusId) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Gets status information by status code or status and substatus codes
     * @param statusId status code
     * @param substatusId substatus code (if not provided, returns only status info)
     * @return Map with status information
     */
    public Map<String, Object> getTrackingInfo(int statusId, Integer substatusId) {
        String statusName = statusNameList.containsKey(statusId) ? statusNameList.get(statusId) : "Undefined";
        Map<String, Object> result = new HashMap<>();
        result.put("statusName", statusName);
        result.put("statusId", statusId);
        result.put("isFinal", isFinal(statusId, substatusId));

        if (substatusId != null) {
            result.put("substatusId", substatusId);
            String substatusName = statusMap.get(String.valueOf(statusId)).get(String.valueOf(substatusId));
            if(StringUtils.isNotBlank(substatusName)){
                result.put("substatusName", substatusName);
            } else {
                result.put("substatusName", "Undefined");
            }
        }

        return result;
    }
}